package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.behavior.dtos.ArticleInfoDto;
import com.heima.model.behavior.dtos.CollectionBehaviorDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmFindNewsCommentDto;
import com.heima.model.wemedia.dtos.WmNewsPageDto;
import com.heima.model.wemedia.dtos.WmUpdateCommentStatusDto;
import com.heima.model.wemedia.vos.WmCommentVo;
import org.apache.commons.net.nntp.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;

    //加载首页
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto){
        //return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,articleHomeDto);

        return apArticleService.load2(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE,true);
    }

    //加载更多
    @PostMapping("loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto articleHomeDto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,articleHomeDto);
    }

    //加载最新
    @PostMapping("loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto articleHomeDto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_NEW,articleHomeDto);
    }

    /**
     * 自媒体端发布 文章同步
     * @param articleDto
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody ArticleDto articleDto){
        return apArticleService.saveArticle(articleDto);
    }

    /**
     * 虚假feign 远程调用获取文章
     * @param id
     * @return
     */
    @GetMapping("get")
    public ApArticle getById(Long id){
        return apArticleService.getById(id);
    }

    /**
     * 行为数据回显
     * @param articleInfoDto
     * @return
     */
    @PostMapping("load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto articleInfoDto){
        return apArticleService.loadArticleBehavior(articleInfoDto);
    }

    /**
     * 远程获取文章配置
     * @param id
     * @return
     */
    @PostMapping("config")
    public ApArticleConfig getArticleConfig(@RequestParam Long id){
        return apArticleService.getArticleConfig(id);
    }

    /**
     * 远程获取文章评论管理列表
     * @param id
     * @return
     */
    @PostMapping("manage")
    PageResponseResult getCommentManageList(@RequestBody WmFindNewsCommentDto dto, @RequestParam Integer id){
        return apArticleService.getCommentManageList(dto,id);
    }

    /**
     * 远程修改文章评论状态
     * @param dto
     * @return
     */
    @PostMapping("comment_status")
    ResponseResult updateCommentStatus(@RequestBody WmUpdateCommentStatusDto dto){
        return apArticleService.updateCommentStatus(dto);
    }

    /**
     * 获取作者的所有文章
     * @param userId
     * @return
     */
    @PostMapping("all")
    List<ApArticle> all(@RequestParam Date beginDate, @RequestParam Date endDate, @RequestParam Integer userId){
        return apArticleService.getAllArticle(beginDate,endDate,userId);
    }

    /**
     * 图文展示
     */
    @PostMapping("newsPage")
    public ResponseResult getNewsPage(@RequestBody WmNewsPageDto dto , @RequestParam Integer wmUserId){
        return apArticleService.getNewsPage(dto,wmUserId);
    }

}
